package com.cuiweiyou.bluemesh.ui;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class GroupInitAdapter extends FragmentPagerAdapter {
    List<GroupInitFragment> fragmentList;
    List<String> groupNameList;

    public GroupInitAdapter(FragmentManager fm) {
        super(fm);

        fragmentList = new ArrayList<>();
        groupNameList = new ArrayList<>();
    }

    public void addGroup(String groupName) {
        if (groupNameList.contains(groupName)) {
            return;
        }

        groupNameList.add(groupName);
        GroupInitFragment group = GroupInitFragment.getInstance(groupName);
        fragmentList.add(group);

        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        return null == fragmentList ? null : fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return null == fragmentList ? 0 : fragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return null == groupNameList ? null : groupNameList.get(position);
    }
}